<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<section class="content-header">
    <h1>领料申请提交</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        流水号
                                    </label>
                                    <label class="control-label">
                                        <input name="orderNo" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入流水号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        制单人
                                    </label>
                                    <label class="control-label">
                                        <input name="makeUserName" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入制单人"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        驳回原因
                                    </label>
                                    <label class="control-label">
                                        <input name="rejectReasons" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入驳回原因"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        制单部门
                                    </label>
                                    <label class="control-label">
                                        <select name="makDeptId" class="form-control">
                                            <option value="" selected="selected">全部</option>
                                            <option th:each="item:${deptList}" th:value="${item.id}" th:text="${item.name}"></option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        提交状态
                                    </label>
                                    <label class="control-label">
                                        <select name="appStatus" class="form-control">
                                            <option value="">全部</option>
                                            <option value="1" selected="selected">未提交</option>
                                            <option value="2">已提交</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">创建时间</label>
                                    <label class="control-label">
                                        <input type="text" class="form-control datepicker" name="startTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="endTime"
                                               readonly="readonly"/></label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
<!--                <div id="toolbar" class="row">-->
<!--                    <button shiro:hasPermission="req:submit:edit" onclick="submit('')" class="btn btn-success">批量提交</button>-->
<!--                </div>-->
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table, tempTable, tempData = new Array(), currentProject;
    $(function () {
        /**
         * 加载列表
         */
        loadTable();
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
    });

    /**
     * 重新加载
     */
    function reloadTable() {
        js.table.refresh(table);
    }

    /**
     * 加载列表
     */
    function loadTable() {
        table = js.table.init({
            url: ctx + "materialRequisition/submitList",
            showColumns: true,
            showExport: true,
            columns: [
                // {
                //     checkbox: true,
                //     width: '30px',
                //     formatter: function (value, row, index) {
                //         if (row.appStatus === 1 || row.appStatus === 4) {
                //             return {disabled: false}
                //         } else {
                //             return {disabled: true}
                //         }
                //     }
                // },
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '流水号', field: 'orderNo',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '制单人', field: 'makeUserName',width: '150',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '制单部门', field: 'makeDeptName',width: '200',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '创建时间', field: 'makCreateTime',width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '提交状态', field: "appStatus",width: '70',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (value === 1) {
                                return '<label class="badge label-default">未提交</label>';
                            } else if (value === 2) {
                                return '<label class="badge label-success">已提交</label>';
                            } else if (value === 3) {
                                return '<label class="badge label-success">审核通过</label>';
                            } else if (value === 4) {
                                return '<label class="badge label-danger">被驳回</label>';
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '驳回原因', field: "rejectReasons",width: '70',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作', width: '180',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if ((row.appStatus === 1 || row.appStatus === 4) && hasP('req:submit:edit')) {
                            elements.push('<a class="btn btn-warning btn-xs" href="/materialRequisition/edit/'+row.id+'">编辑</a>');
                            elements.push('<button class="btn btn-success btn-xs" onclick="submit(' + row.id + ')">提交</button>');
                            elements.push('<button class="btn btn-danger btn-xs" onclick="remove(' + row.id + ')">删除</button>');
                        }
                        // if(hasP('req:submit:view')){
                        //     elements.push('<a class="btn btn-info btn-xs" href="/materialRequisition/view/'+row.id+'">查看</a>');
                        // }
                        return elements.join('');
                    }
                }
            ]
        });
    }
    /**
     * 删除
     */
   function remove(id){
        js.confirmPost({
            content: "尊敬的用户，您确认要删除此领料申请吗？",
            url: ctx + 'materialRequisition/delete',
            data: {
                id:id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                } else {
                    js.modal.warning(result.msg);
                }
                js.table.refresh(table);
            }
        });
   }
    /**
     * 提交
     */
    function submit(idStr) {

        // js.post({
        //     url: ctx + 'materialRequisition/submit',
        //     type: 'post',
        //     traditional: true,            // 阻止深度序列化， 使参数可以使用数组
        //     dataType: 'json',
        //     contentType: "application/x-www-form-urlencoded",
        //     data: {
        //         idStr: idStr
        //     },
        //     async: true,                // 异步执行
        //     success: function (result) {
        //         if (result.type === web_status.SUCCESS) {
        //             js.modal.success(result.msg);
        //         } else {
        //             js.modal.warning(result.msg);
        //         }
        //         js.table.refresh(table);
        //     },
        //     error: function () {
        //         js.modal.fail();
        //     }
        // });

        // if(idStr===''){
        //     let arr = js.table.selectColumns(table, "id");
        //     idStr=arr.join(',');
        // }
        $.post(
            ctx+'materialRequisition/checkWhetherTheApprovalConfigurationOfMaterialRequisitionIsCompletelyCorrect',
            {

            },
            function (result){
                if (result.type === web_status.SUCCESS) {
                    js.post({
                        url: ctx + 'materialRequisition/submit',
                        type: 'post',
                        traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                        dataType: 'json',
                        contentType: "application/x-www-form-urlencoded",
                        data: {
                            idStr: idStr
                        },
                        async: true,                // 异步执行
                        success: function (result) {
                            if (result.type === web_status.SUCCESS) {
                                js.modal.success(result.msg);
                            } else {
                                js.modal.warning(result.msg);
                            }
                            js.table.refresh(table);
                        },
                        error: function () {
                            js.modal.fail();
                        }
                    });
                } else {
                    js.modal.warning(result.msg);
                }
            }
        )
    }

    /**
     * 重新加载
     */
    function reLoad() {
        js.table.refresh(table);
    }
</script>
</body>
</html>